<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
<input type="text" placeholder="请输入0-100之间的整数" id="i1">
<input type="button" value="猜一猜" onclick="f()">
<div>结果：<span></span></div>

<script>
    //得到0-100随机整数
    let x = parseInt(Math.random()*101);
    let i = document.querySelector("#i1");
    let s = document.querySelector("span");
    let num = 0;
    function f() {
        num++;
        let y = i.value;
        if (isNaN(y)){
            s.innerText = "傻逼！ 重输"
            return;
        }
        if (y>x){
            s.innerText = "猜大了！"
        }else if (y<x){
            s.innerText = "猜小了！"
        }else {
            s.innerText = "你在第"+num+"次终于猜对了！"
        }
    }
</script>
</body>
</html>